package com.clickpaas.materialsprocurement.service.Impl;

import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.PurchaseLineDTOResponse;
import com.clickpaas.materialsprocurement.dao.PurchaseLineDao;
import com.clickpaas.materialsprocurement.entity.PurchaseOrderLineEntity;
import com.clickpaas.materialsprocurement.service.PurchaseLineService;
import com.clickpaas.materialsprocurement.utils.DataInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class PurchaseLineServiceImpl implements PurchaseLineService {
    @Resource
    private PurchaseLineDao purchaseLineDao;
    /**
     * 获取采购订单行数据
     * @return
     */
    public List<PurchaseLineDTOResponse> getPurchaseLineInfo(PurchaseOrderLineEntity purchaseOrderLineEntity) {

        List<PurchaseLineDTOResponse> reUnitList;
        try {
            /**
             * 入参为空,不查询
             */
            if (null == purchaseOrderLineEntity || DataInfoUtil.isAllFieldNull(purchaseOrderLineEntity)){
                return null;
            }else {
                reUnitList = purchaseLineDao.getPurchaseLineByCondtion(purchaseOrderLineEntity);
            }
        } catch (Exception e) {
            log.info("入参对象异常,请检查：【{}】,报错信息：【{}】",purchaseOrderLineEntity,e);
            return null;
        }
        if (null != reUnitList && reUnitList.size()>0){
            return reUnitList;
        }
        return null;
    }

    /**
     * 采购订单行数据转换为bean
     * @return
     */
    public List<PurchaseOrderLineEntity> purchaseLineDataConver(List<PurchaseLineDTOResponse> list) {
        return DataInfoUtil.castListCopy(list,PurchaseLineDTOResponse.class,PurchaseOrderLineEntity.class);
    }

    /**
     * 采购订单行数据入库
     *
     * @param purchaseOrderLineEntity
     * @return
     */
    @Override
    public Boolean insertPurchaseLine(PurchaseOrderLineEntity purchaseOrderLineEntity) {
        if (null == purchaseOrderLineEntity)return false;
        return purchaseLineDao.insertPurchaseLine(purchaseOrderLineEntity);
    }
}
